<%@ page import="org.apache.struts.action.Action"%>
<%@page import="com.mbbmap.util.StringUtils"%>
<%@ page import = "java.io.*" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.util.Map" %>
<%@ page import = "java.util.HashMap" %>
<%@ page import="com.mbbmap.app.manager.*" %>
<%@ page import="com.mbbmap.app.EbppKeys" %>
<%@ page import="com.mbbmap.util.*" %>
<%@ page import = "com.mbbmap.security.dao.*" %>
<%@ page import = "com.mbbmap.app.dao.UserDao" %>

<%
String msg = StringUtils.NullSafe((String) request.getAttribute("msg"));
String msg_id = StringUtils.NullSafe((String) request.getAttribute("msg_id"));
System.out.println("testing reach SecAuditTrail.jsp 01");
String userid = StringUtils.NullSafe((String) request.getAttribute("userid"));
String pass1 = StringUtils.NullSafe((String) request.getAttribute("pass1"));
String pass2 = StringUtils.NullSafe((String) request.getAttribute("pass2"));
String recordsearch = StringUtils.NullSafe((String) session.getAttribute("recordsearch"));
ArrayList arrayresult = (ArrayList) session.getAttribute("auditresult");
ArrayList arrayInactive = (ArrayList) request.getAttribute("Inactiveresult");
boolean showParam = false;
String msgColor = "red";
String strAuditAction = StringUtils.NullSafe((String) request.getAttribute("auditaction"));

if (msg_id.equalsIgnoreCase("MSG001") || msg_id.equalsIgnoreCase("MSG002"))
	showParam = true;

if (msg_id.equalsIgnoreCase("MSG999"))
	msgColor = "green";
System.out.println("testing reach SecAuditTrail.jsp 02");

ArrayList secGroupAccessList = (ArrayList) session.getAttribute(Constants.LOGON_ACCESS_LIST);
SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);
String sUserName = oSecUserDao.getUserName();
String lastLogonDateTime = (String) session.getAttribute(Constants.LAST_LOGON_DATETIME);
String selected = "sec008";
int iSec001 = 0;
int iSec002 = 0;
int iSec003 = 0;
int iSec004 = 0;
int iSec005 = 0;
int iSec006 = 0;
int iSec007 = 0;
int iSec008 = 0;
System.out.println("testing reach SecAuditTrail.jsp 03");

for(int i=0;i<secGroupAccessList.size();i++){
	SecAccessDao secaccessDao = (SecAccessDao)secGroupAccessList.get(i);
	String strModuleCode  = secaccessDao.getModuleCode();
	if(strModuleCode.equals("SEC001"))
		iSec001 = 1;
	if(strModuleCode.equals("SEC002"))
		iSec002 = 1;
	if(strModuleCode.equals("SEC003"))
		iSec003 = 1;
	if(strModuleCode.equals("SEC004"))
		iSec004 = 1;
	if(strModuleCode.equals("SEC005"))
		iSec005 = 1;
	if(strModuleCode.equals("SEC006"))
		iSec006 = 1;
	if(strModuleCode.equals("SEC007"))
		iSec007 = 1;
	if(strModuleCode.equals("SEC008"))
		iSec008 = 1;
}
System.out.println("testing reach SecAuditTrail.jsp 04");
System.out.println("testing reach SecAuditTrail.jsp 05 strAuditAction="+strAuditAction);


%>

<html>
<head>
<link rel="stylesheet" href="resource/mbb_sec_global.css" type="text/css" />
<link href="resource/style.css" rel="stylesheet" type="text/css">

<script type="text/javascript">
	    window.history.forward();
	    function noBack() { window.history.forward(); }
	</script>
<style type="text/css"></style></head>


</head>
<script type="text/javascript" src="resource/ezcalendar.js"></script>
<link rel="stylesheet" type="text/css" href="resource/ezcalendar.css" />

<%
	//on jsp load
%>

<body class="home" onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
<%java.text.DateFormat df = new java.text.SimpleDateFormat("MM/dd/yyyy"); %>
<%java.text.DateFormat df2 = new java.text.SimpleDateFormat("dd/MM/yyyy"); %>
	<a name="top"></a>

<SCRIPT LANGUAGE="JavaScript1.2">

function auditTrail() {
		//alert("Start get record");
		//alert(document.getElementById("record").value);
		if (document.GetGroupLevelForm.record.value==null||document.GetGroupLevelForm.record.value==""){
		alert("Insert user name.")
		}	
		else if( document.GetGroupLevelForm.input1.value===""||document.GetGroupLevelForm.input1.value===null){
		alert("Select start date.")
	    }
		else if ( document.GetGroupLevelForm.input2.value==""||document.GetGroupLevelForm.input2.value===null){
		alert("Select end date.")
		}
		if ( document.GetGroupLevelForm.record.value!=null||document.GetGroupLevelForm.record.value!=""){
		if ( document.GetGroupLevelForm.input1.value!=null&& document.GetGroupLevelForm.input2.value!=null){
		var stmtdtselFR = document.GetGroupLevelForm.input1.value;
		var stmtdtselTO = document.GetGroupLevelForm.input2.value;
		var x = document.getElementById("record").value;
		document.GetGroupLevelForm.rptdatefr.value	= stmtdtselFR;
		document.GetGroupLevelForm.rptdateto.value	= stmtdtselTO;
		document.GetGroupLevelForm.recordsearch.value	= x;
		document.GetGroupLevelForm.action='<%=response.encodeURL("SecAuditTrail.do?dispatch=init")%>';
		document.GetGroupLevelForm.submit();
		}
		}
   }
   
   
function listUser() {
		document.GetGroupLevelForm.action='<%=response.encodeURL("SecAuditTrail.do?dispatch=listinUsr")%>';
		document.GetGroupLevelForm.submit();
  } 
</SCRIPT>

<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->

<div id="bgWrapper">
		<div id="container">
		
					<div id="titleBar">
						<ul class="topBar">
							<li class="goBackBt"><a href="<%=request.getContextPath()%>/ShowSecurityHome.do?dispatch=init"></a></li>
							<li>
							  <h1>Audit Trail</h1></li>
						</ul>
					</div>
		
					<div id="fullcontent">
		
						<!-- Security Navigation -->
						<%@ include file="SecurityNavigation.jsp" %>	
						<!-- End SecurityNavigation -->
			
			
						<div id="contentRightIn">
									
							<div id="moduleContainer">
							
							
									<!--  Module Title -->
									<table align="center" width=100% border="5" rules="cols" class="tblDetails">
										<thead>
											<tr>
												<th colspan="4">
													<h4>Audit Trail</h4>
												</th>
											</tr>
										</thead>
											
										<tr class="even">
											<td colspan="2" align="center" style="text-align:center !important;">
												This module shows the log.
												<p style="font-weight:bold;color: <%=msgColor%> !important;"><%=msg%></p>
											</td>
										</tr>
									</table>

									<!--  Audit Trail Parameters -->
									<form name="GetGroupLevelForm" action="" method="post" autocomplete="off">
									<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
									<input type="hidden" name="rptdatefr" value="">
									<input type="hidden" name="rptdateto" value="">
									<input type="hidden" name="recordsearch" value="">
										<table align="center" class="tblDetails" width=100% border="0" rules="cols">
											<thead class="th1">
												<tr>
													<th colspan="3">
														<div class="sectionTableTitle">
															<h3>Security Groups</h3>
														</div>
													</th>
											</thead>
											
											<tr class="headerD"  style="border: thin solid"	>
												 <td width="28%">Select Date:</td>
   												 <td width="72%">
   												 
   												 	From: Date<input maxlength="10" disabled="disabled" size="25" name="input1" id="input1" value="<%=df2.format(new java.util.Date())%>">
													<a style="text-decoration:none;" href="#" onclick="showCalendar('input1')"><img align="middle" src="resource/cal.gif" alt="Choose date" border="0" /></a> 
													
													To: <input maxlength="10" disabled="disabled" size="25" name="input2" id="input2" value="<%=df2.format(new java.util.Date())%>">
													<a style="text-decoration:none;" href="#" onclick="showCalendar('input2')"><img align="middle" src="resource/cal.gif" alt="Choose date" border="0" /></a></td>
											</tr>
											<tr class="headerD" style="border: thin solid">
											 	<td width="28%">Search By User: </td>
   											 	<td width="72%"><input type="text" autocomplete="off" id="record" value=<%=recordsearch %>> <input type="submit" value="Get Report" onClick="auditTrail()"/></td>
											</tr>
											<tr class="headerD" style="border: thin solid">
											 	<td width="28%">List of Inactive User: </td>
   											 	<td width="72%"><input type="submit" value="Get Report" onClick="listUser()"/></td>
											</tr>
											
											</table>
										</Form>
<%
System.out.println("testing reach SecAuditTrail.jsp 06 strAuditAction="+strAuditAction);
	if(strAuditAction.equals("searchAudit")){
%>								
								
									<!-- Audit Trail Data Table -->	
									<form name="frmAuditTrail" action="" method="post" autocomplete="off">
									<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
									<input type="hidden" name="sremgroup" value="">
									<table align="center" class="tbldetails" width=100% border="2" rules="cols">
										<thead class="th1">
											<tr>
												<th colspan="4">
													<div class="sectionTableTitle">
														<h3>Audit Log</h3>
													</div>
												</th>
										</thead>
										<tr class="headerD" style="border: thin solid">
											<td width="10%" class="center_note">Date</td>
											<td width="30%" class="center_note">Event</td>
											<td width="30%" class="center_note">Code</td>
											<td width="30%" class="center_note">Remark</td>
										</tr>
										<%if (arrayresult!=null) {%>
							            <%for(int i=4; i<=arrayresult.size(); i+=4) {
							            	String element1 = (String)arrayresult.get(i-4);
							            	String element2 = (String)arrayresult.get(i-3);
							            	String element3 = (String)arrayresult.get(i-2);
							            	String element4 = (String)arrayresult.get(i-1);%>
				 							<tr style="border: thin solid">
				 								<td width="10%" class="center_note"><%=element1%></td>
												<td width="30%" class="center_note"><%=element2%></td>
												<td width="30%" class="center_note"><%=element3%></td>
												<td width="30%" class="center_note"><%=element4%></td>
											</tr>
										<%}} %>
									</table>
								</form>
<%
}
%>							
				<%
System.out.println("testing reach SecAuditTrail.jsp 07 strAuditAction="+strAuditAction);
				
if(strAuditAction.equals("listinactive")){
%>							
									<!-- Audit Trail Data Table -->	
									<form name="frmUser" action="" method="post" autocomplete="off">
									<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
									<table align="center" class="tbldetails" width=100% border="2" rules="cols">
										<thead class="th1">
											<tr>
												<th colspan="4">
													<div class="sectionTableTitle">
														<h3>List of Inactive Users</h3>
													</div>
												</th>
										</thead>
										<tr class="headerD" style="border: thin solid">
											<td width="10%" class="center_note">User ID</td>
											<td width="30%" class="center_note">User Name</td>
											<td width="30%" class="center_note">Last Login Date</td>
											<td width="30%" class="center_note">Enabled</td>
										</tr>
										<%if (arrayInactive!=null) {%>
										<% for(int i=0; i<arrayInactive.size(); i++) {
											UserDao usr = (UserDao)arrayInactive.get(i);

										%>

				 							<tr style="border: thin solid">
				 								<td width="10%" class="center_note"><%=usr.getUserLogin()%></td>
												<td width="30%" class="center_note"><%=usr.getUserName()%></td>
												<td width="30%" class="center_note"><%=usr.getRemark()%></td>
												<td width="30%" class="center_note"><%=usr.getUserEnabled()%></td>
											</tr>
										
										<%}%>										
										<%}%>
										
										</table>
										</form>


<%
}
%>			
							</div> <!--  moduleContainer END -->
						</div>
		
					<!-- Footer -->
					<%@ include file="/jsp/common/Footer.jsp" %>	
					<!-- End Footer -->
					</div>




</body>
</html>